package com.study.data.sort;

/**
 * @program: java-study-of-learner
 * @description: 选择排序
 * @author: future
 * @create: 2020-11-21 17:16
 **/
public class SelectionSort {

    /**
     * 简单的选择排序
     */
    public void sort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int temp = i;
            //1.找出最小值
            for (int j = temp + 1; j < arr.length; j++) {
                if (arr[temp] > arr[j]) {
                    temp = j;
                }
            }
            //2.赋值操作
            if (i != temp) {
                int saveTemp = arr[i];
                arr[i] = arr[temp];
                arr[temp] = saveTemp;
            }

        }
    }


}
